package com.gd.iot.energy.controller.datamanage;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.datamanage.vo.InstructionPageVO;
import com.gd.iot.energy.pojo.statistics.vo.CalledDetailVO;
import com.gd.iot.energy.pojo.statistics.vo.ReceiveDetailVO;
import com.gd.iot.energy.service.datamanage.InstructionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据管理-数据采集-收发记录-指令收发记录
 *
 * @author kris
 * @date Created at 2020/8/13 10:50
 */
@Api(value = "数据管理-数据采集-收发记录-指令收发记录",tags = "数据管理-数据采集-收发记录-指令收发记录")
@RestController
@RequestMapping("/admin/instruction")
public class InstructionController {

    @Autowired
    private InstructionService instructionService;

    @ApiOperation("指令收发记录分页列表")
    @SystemLogRecordMonitor("指令收发记录分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "equipmentType", value = "设备类型 (GENERAL, 0)" +
                    "(LORAWAN, 1)" +
                    "(NBIOT, 2)" +
                    "(RTU, 3)", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesNum", value = "客户编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaName", value = "区域名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesAddress", value = "表计地址", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "archivesName", value = "户名", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "beginDate", value = "开始时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "endDate", value = "结束时间", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getInstructionPageVO")
    public ResponseEntity<PageVO<InstructionPageVO>> getInstructionPageVO(
            @RequestParam(value = "equipmentType",required = false)Integer equipmentType,
            @RequestParam(value = "areaName",required = false)String areaName,
            @RequestParam(value = "archivesNum",required = false)String archivesNum,
            @RequestParam(value = "archivesAddress",required = false)String archivesAddress,
            @RequestParam(value = "archivesName",required = false)String archivesName,
            @RequestParam(value = "beginDate",required = false)String beginDate,
            @RequestParam(value = "endDate",required = false)String endDate,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "create_date") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "desc") String orderType
    ) {
        PageVO<InstructionPageVO> pageVO = instructionService.getInstructionPageVO(equipmentType,archivesNum,areaName,
                archivesAddress,archivesName,beginDate,endDate,pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("指令发送-详细")
    @SystemLogRecordMonitor("指令发送-详细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "指令id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/calledDetail")
    public ResponseEntity<CalledDetailVO> calledDetail(@RequestParam(value = "id",required = true)Integer id){
        CalledDetailVO calledDetailVO = instructionService.calledDetail(id);
        return new ResponseEntity<>(calledDetailVO);
    }

    @ApiOperation("指令接收-详细")
    @SystemLogRecordMonitor("指令接收-详细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "指令id", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/receiveDetail")
    public ResponseEntity<ReceiveDetailVO> receiveDetail(@RequestParam(value = "id",required = true)Integer id){
        ReceiveDetailVO calledDetailVO = instructionService.receiveDetail(id);
        return new ResponseEntity<>(calledDetailVO);
    }
}
